<template>
	<view class="wrap">
		<view class="card_body">
			<view class="card_cell">
				<view class="card_title">
					<text class="must">*</text>
					抬头名称
				</view>
				<view class="card_inp">
					<input class="inpbox" v-model="params.School" type="text" placeholder="请输入抬头名称" />
				</view>
			</view>
			<view class="card_cell">
				<view class="card_title">
					<text class="must">*</text>
					税号
				</view>
				<view class="card_inp">
					<input class="inpbox" v-model="params.Class" type="text" placeholder="请输入税号" />
				</view>
			</view>
			<!-- <picker mode="selector" :range="sexEntry" @change="changeSexFun">
				<view class="card_cell">
					<view class="card_title">
						<text class="must">*</text>
						性别
					</view>
					<view class="card_inp">
						<input class="inpbox" v-model="params.Sex" type="text" disabled placeholder="请选择性别" />
						<image src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/17453073622021044.png" mode="heightFix"></image>
					</view>
				</view>				
			</picker> -->
			<view class="card_cell">
				<view class="card_title">
					<text class="must">*</text>
					电话号码
				</view>
				<view class="card_inp">
					<input class="inpbox" v-model="params.Mobile" type="tel" placeholder="公司电话(选填)" />
				</view>
			</view>
			<view class="card_cell">
				<view class="card_title">
					<text class="must">*</text>
					开户银行
				</view>
				<view class="card_inp">
					<input class="inpbox" v-model="params.Bank" type="text" placeholder="开户银行(选填)" />
				</view>
			</view>
			<view class="card_cell">
				<view class="card_title">
					<text class="must">*</text>
					银行账户
				</view>
				<view class="card_inp">
					<input class="inpbox" v-model="params.Mobile" type="tel" placeholder="银行账户(选填)" />
				</view>
			</view>
		</view>
		
		<view class="card_body">
			<view class="title_body">
				单位地址
			</view>
			<picker mode="region" :value="['广东省','广州','天河']" @change="chooseAddressInfo">
				<view class="card_cell">
					<view class="card_title">
						
						所在地区
					</view>
					<view class="card_inp">
						<input class="inpbox" :style="addressinfo== '请选择地区' ? 'color: #a8a8a8;' :''" v-model="addressinfo" type="text" disabled placeholder="请选择所在地区" />
						<image src="https://giftapp.oss-cn-shenzhen.aliyuncs.com/upload/17453073622021044.png" mode="heightFix"></image>
					</view>
				</view>				
			</picker>
			<view class="card_cell card_textarea">
				<view class="card_title">
					
					详细地址
				</view>
				<view class="card_inp">
					<textarea type="text" v-model="params.Address" disable-default-padding maxlength="50" placeholder="请输入详细地址" />

				</view>
			</view>
		</view>
		
		<view style="height: 160rpx;"></view>
		<view class="saveBox">
			<view class="btn saveBtn" @click="submit">{{mold==0?'添加':mold==1?'保存':''}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				region:[],
				mold:0,
				params:{
					Company:'',// 企业名称
					TFN:'',// 税号
					Mobile:'',// 联系电话
					Province:'',// 省份
					City:'',// 城市
					Area:'',// 区域
					Address:'',// 详细地址
					Bank:'',// 开户银行
					BankAccount:'',// 银行账号
				},
				sexEntry:['男','女']
			};
		},
		onLoad(e){
			this.mold = e.mold
			uni.setNavigationBarTitle({
				title: this.mold==0 ? '添加班级' : this.mold==1 ? '编辑班级' : ''
			})
			if(this.mold==1){
				this.getEditInfo()
			}
		},
		computed: {
			addressinfo(){
				let list = this.region;
				if (list[0] == list[1]) {
					list.splice(0,1)
				}
				return list.join('') || '请选择地区';
			},
		},
		methods:{
			async getEditInfo(){
				let res = await this.$api.post('/Class/MyClass')
				this.params = res.data || false
				if(this.params){
					this.region = [
						this.params.Province || '',
						this.params.City || '',
						this.params.Area || '',
					]
				}
			},
			chooseAddressInfo(e) {
				console.log('picker发送选择改变，携带值为', e)
				this.region = e.detail.value;
				if(this.region.length){
					this.params.Province = this.region[0]
					this.params.City = this.region[1] || ''
					this.params.Area = this.region[2] || ''
				}
				
			},
			changeSexFun(e){
				console.log(e.detail.value);
				this.params.Sex = this.sexEntry[e.detail.value]
			},
			async submit(){
				if(!this.params.School){
					this.$pv.msg('请输入学校名称')
					return
				}
				if(!this.params.Class){
					this.$pv.msg('请输入班级名称')
					return
				}
				if(!this.params.StudentName){
					this.$pv.msg('请输入学生姓名')
					return
				}
				if(!this.params.Sex){
					this.$pv.msg('请选择性别')
					return
				}
				// if(!this.params.Mobile){
				// 	this.$pv.msg('请输入电话号码')
				// 	return
				// }
				// if(!this.params.Bank){
				// 	this.$pv.msg('请输入开户银行)
				// 	return
				// }
				if(!this.params.Province){
					this.$pv.msg('请选择所在地区')
					return
				}
				if(!this.params.Address){
					this.$pv.msg('请输入详细地址')
					return
				}
				
				let url;
				if(this.mold==0){
					url = '/Class/Add'
				}else if(this.mold==1){
					url = '/Class/Edit'
				}
				let res = await this.$api.post(url,this.params)
				if(res.code==0){
					if(this.mold==0){
						this.$pv.msg('添加完成')
					}
					if(this.mold==1){
						this.$pv.msg('保存完成')
					}
					setTimeout(()=>{
						uni.navigateBack()
					},700)
				}else{
					this.$pv.msg(res.message)
				}
			}
		}
	}
</script>

<style lang="scss">
page{
	background-color: #f6f6f6;
}
.wrap{
	.card_body{
		margin-bottom: 20rpx;
		.title_body{
			font-size: 30rpx;
			font-weight: bold;
			color: #000;
			margin:0 0 8rpx 24rpx;
		}
		.card_cell{
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 110rpx;
			padding: 0 24rpx;
			border-bottom: 1rpx solid #E4E4E4;
		
			.card_title{
				font-size: 32rpx;
				color: #333333;
				width: max-content;
				min-width: max-content;
				.must{
					color: #fc3c4a;
				}
			}
			.card_inp{
				flex: 1;
				height: 100%;
				display: flex;
				align-items: center;
				.inpbox{
					flex: 1;
					margin-left: 24rpx;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: flex-end;
				}
				input{
					display: block !important;
					text-align: right;
				}
				image{
					margin-left: 8rpx;
					width: 20rpx;
					height: 30rpx;
				}
			}
			
		}
		.card_textarea{
			padding: 24rpx;
			height: 170rpx;
			.card_title{
				justify-content: flex-start;
				height: 100%;
			}
			.card_inp{
				textarea{
					width: 100%;
					min-height: 120rpx;
					height: 120rpx;
					padding: 0;
					font-size: 32rpx;
					color: #000;
					flex: 1;
					margin-left: 20rpx;
					box-sizing: border-box;
					text-align: right;
				}
			}
			
		}
	}
	
	.saveBox {
		position: fixed;
		width: 100%;
		height: 158rpx;
		box-sizing: border-box;
		left: 0;
		bottom: 0;
		padding: 20rpx 50rpx;
		background-color: #fff;
		display: flex;
		justify-content: center;
	
		.saveBtn {
			width: 670rpx;
			height: 88rpx;
			background: linear-gradient(98deg, #a6c8ff 0%, #5d8bf8 100%);
			border-radius: 44rpx;
			font-weight: bold;
			font-size: 32rpx;
			color: #FFFFFF;
		}
	}
}
</style>
